package com.itany.book.controller;

import com.github.pagehelper.PageInfo;
import com.itany.book.pojo.Order;
import com.itany.book.service.OrderService;
import com.itany.book.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Author:yaozhiyuan0117@163.com
 * Time:2019/12/26 8:03
 * Describe:
 * version:1.0
 */

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @RequestMapping("/findAll")
    @ResponseBody
    public Map findAll(Integer page, Integer rows, String no, String alipayno){
        System.out.println("-----------------");
        System.out.println(no);
        System.out.println(alipayno);

        HashMap map = new HashMap<>();
        PageInfo<Order> info = orderService.findAll(page, rows, no, alipayno);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }


    @RequestMapping("/findById")
    @ResponseBody
    public ResponseResult findById(Integer id){
        Order order = orderService.findById(id);
        return ResponseResult.success(order);
    }


    @RequestMapping("/modifyOrder")
    @ResponseBody
    public ResponseResult modifyOrder(Integer id, Integer flag){
        orderService.modifyOrder(id, flag);
        return ResponseResult.success();
    }
}
